<?php


namespace Admin\Event;
use Think\Controller;

class OrderEvent extends Controller
{
    //查询所有订单
    public function queryAllOrder ()
    {
        $order = M("order");
        $count = $order->count("id");//总记录
        $page = new \Think\Page($count,5);//每页显示  5 条数据
        //设置分页属性
        $show = $page -> show(); //分页显示输出
        // 进行分页数据查询 注意limit方法的参数要使用Page类的属性
        $orderlist = $order->limit($page->firstRow.",".$page->listRows)->select();
        $data['show'] = $show;
        $data['list'] = $orderlist;
        return $data;
    }
    //根据订单id查询订单详情
    public function queryOrderDetail()
    {
        $order_id = I("get.order_id");
        $orderDetail = M("orderdetail");
        $res = $orderDetail->where("order_id='$order_id'")->select();
        foreach($res as $key => $value){
            $goods_id = $value['goods_id'];
            //根据goods_id查询商品名 商品价格 和 要购买的数量
            $goods = M("goods");
            $data = $goods
                ->alias("g")->join('shopping_goodsimg i on i.goods_id=g.id')
                ->field(array("g.id","g.name","i.img"))
                ->where("g.id=$goods_id and i.is_main=1")->find();
            $data['num'] = $value["num"];
            $data['price'] = $value["price"];
            $orderData[$key] = $data;
        }

        return $orderData;
    }

    //查询所有优惠券
    public function queryAllCoupon ()
    {
        $coupon = M("coupon");
        return $coupon->field(array("cou_pri","id"))->select();

    }
    //发货
    public function send ()
    {
        $order_id = I("get.order_id");
        $order = M("order");
        $res = $order->where("order_id='$order_id'")->setField("is_deliver",1);
        return $res;
    }
}






